package com.asm.DBloader;

import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class ASM_FAreaDS {
	private SQLiteDatabase dB;
	private ASM_DB dbHelper;
	Context context;
	
	
	public ASM_FAreaDS(Context context) {
		this.context = context;
		dbHelper  = new ASM_DB(context);
		
	}
	
	public void open() throws SQLException
	{
		dB = dbHelper.getWritableDatabase();
	}
	
	public int Create(ASM_FArea det) 
	{
		
		int count =0;
		
		if(dB == null){
			open();
		}else if(!dB.isOpen()){
			open();
		}
		
		
		ContentValues values = new ContentValues();
		values.put(ASM_DB.asmAr_AreaCode, det.getAsmAr_AreaCode());
		values.put(ASM_DB.asmAr_AreaName, det.getAsmAr_AreaName());
		values.put(ASM_DB.asmAr_RegCode,det.getAsmAr_RegCode());
		values.put(ASM_DB.asmAr_DealCode, det.getAsmAr_DealCode());


		
		count = (int) dB.insert(ASM_DB.ASM_FAREA, null, values);

		dB.close();
		return count;
		
	}
	public ArrayList<String> getArea() 
	{
		if (dB == null) {
			open();
		} else if (!dB.isOpen()) {
			open();
		}
		
		ArrayList<String> Details = new ArrayList<String>();
	
		String selectQuery = "select AreaCode,AreaName from fArea";
		
		Cursor cursor = null;
		cursor = dB.rawQuery(selectQuery, null);
		
		while(cursor.moveToNext())
		{
		
			String namecode = cursor.getString(1)+" -:- "+cursor.getString(0);
			Details.add(namecode);
			
			
			
		}
		
		return Details;
	}

}
